<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/11/2
 * Time: 20:23
 */

class PushInfo_model extends MY_Model
{
    function push_info($body)
    {
        $body = (json_decode($body));
        $query = null;
        $error = null;
        switch ($body->type) {
            case 'zuowen':
                $tid = 1;
                $sid = $body->sid;
                $gid = $body->class[0];
                $count = $body->count;
                $leam = $body->leam;
                $rep = $body->rep;
                $date = $body->date;
                $sql = /** @lang text */
                    "insert  into `ws_task_zuowen`(`sid`,`gradeId`,`count`,`leam`,`rep`,`tenantId`,`last_date`,`cid`) values ($sid,$gid,$count,$leam,$rep,$tid,'$date',(SELECT id FROM ws_class_zuowen WHERE studentId=$sid))";
                $query = $this->db->query($sql);
                $error = $this->db->error();
                break;
            case 'aoshu':
                $tid = 1;
                $sid = $body->sid;
                $gid = $body->class[0];
                $count = $body->count;
                $leam = $body->leam;
                $rep = $body->rep;
                $date = $body->date;
                $sql = /** @lang text */
//                    "insert  into `ws_task_aoshu`(`sid`,`gradeId`,`count`,`leam`,`rep`,`tenantId`,`last_date`) values ($sid,$gid,$count,$leam,$rep,$tid,'$date')";
                    "insert  into `ws_task_aoshu`(`sid`,`gradeId`,`count`,`leam`,`rep`,`tenantId`,`last_date`,`cid`) values ($sid,$gid,$count,$leam,$rep,$tid,'$date',(SELECT id FROM ws_class_aoshu WHERE studentId=$sid))";
                $query = $this->db->query($sql);
                $error = $this->db->error();
                break;
            case 'shufa':
                $tid = 1;
                $sid = $body->sid;
                $gid = $body->class[0];
                $count = $body->count;
                $leam = $body->leam;
                $rep = $body->rep;
                $date = $body->date;
                $sql = /** @lang text */
//                    "insert  into `ws_task_shufa`(`sid`,`gradeId`,`count`,`leam`,`rep`,`tenantId`,`last_date`) values ($sid,$gid,$count,$leam,$rep,$tid,'$date')";
                    "insert  into `ws_task_shufa`(`sid`,`gradeId`,`count`,`leam`,`rep`,`tenantId`,`last_date`,`cid`) values ($sid,$gid,$count,$leam,$rep,$tid,'$date',(SELECT id FROM ws_class_shufa WHERE studentId=$sid))";
                $query = $this->db->query($sql);
                $error = $this->db->error();
                break;
            case 'outline':
                $kecheng = $body->kecheng;
                $grade = $body->class[0];
                $class = $body->class[1];
                $count = $body->count;
                $outline = $body->outline;
                $sql = null;
                if ($kecheng === 'zuowen') {
                    $sql = /** @lang text */
                        "insert  into `ws_dg_zuowen`(`content`,`classId`,`count`,`gradeId`,`tenantId`) values ('$outline',$class,$count,$grade,1)";
                } elseif ($kecheng === 'aoshu') {
                    $sql = /** @lang text */
                        "insert  into `ws_dg_aoshu`(`content`,`classId`,`count`,`gradeId`,`tenantId`) values ('$outline',$class,$count,$grade,1)";
                } elseif ($kecheng === 'shufa') {
                    $sql = /** @lang text */
                        "insert  into `ws_dg_shufa`(`content`,`classId`,`count`,`gradeId`,`tenantId`) values ('$outline',$class,$count,$grade,1)";
                }
                $query = $this->db->query($sql);
                $error = $this->db->error();
                break;
            default:
                break;
        }
        if ($query) {
            return json_encode(array('result' => SUCCESS, 'msg' => '添加成功！', 'code' => 0));
        } else {
            return json_encode(array('result' => ERROR, 'msg' => '添加失败！', 'code' => $error['code']));
        }
    }
}